home *** CD-ROM | disk | FTP | other *** search
- /* audio.c */
-
-
- /* things for 'beep' support */
-
- /* This code is from Dave Wecker's vt100 2.7 */
- #include <exec/types.h>
- #include <exec/exec.h>
- #include <exec/memory.h>
- #include <devices/audio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #define BEEPSIZE 10L
- #define BEEPFREQ 1000L
- #define COLORCLOCK 3579545L
-
-
- struct IOAudio *Audio_Request = 0;
- struct MsgPort *Audio_Port = NULL;
- UBYTE *BeepWave = 0;
- UBYTE Audio_AllocMap[4] = { 1, 8, 2, 4 };
- short beepok = 1;
-
- initbeep()
- {
- Audio_Request = (struct IOAudio *)AllocMem((long)sizeof(*Audio_Request),
- (long)(MEMF_CHIP|MEMF_CLEAR));
- if(Audio_Request == 0) {
- beepok = 0;
- return(1);
- }
-
- BeepWave = AllocMem(BEEPSIZE,(long)(MEMF_CHIP|MEMF_CLEAR));
- if(BeepWave != 0) BeepWave[0] = 100;
- else {
- beepok = 0;
- return(1);
- }
- Audio_Port = CreatePort((UBYTE *)"Audio Port",0L);
-
- Audio_Request->ioa_Request.io_Message.mn_ReplyPort = Audio_Port;
- Audio_Request->ioa_Request.io_Message.mn_Node.ln_Pri = 85;
- Audio_Request->ioa_Data = Audio_AllocMap;
- Audio_Request->ioa_Length = (ULONG) sizeof(Audio_AllocMap);
-
- if(OpenDevice((UBYTE *)AUDIONAME,0L,
- (struct IORequest *) Audio_Request,0L)) {
- ttputs("can't open Audio Device\n");
- beepok = 0;
- return(1);
- }
-
- Audio_Request->ioa_Request.io_Command = CMD_WRITE;
- Audio_Request->ioa_Request.io_Flags = ADIOF_PERVOL;
- Audio_Request->ioa_Data = BeepWave;
- Audio_Request->ioa_Length = BEEPSIZE;
- Audio_Request->ioa_Period = COLORCLOCK / (BEEPSIZE * BEEPFREQ);
- Audio_Request->ioa_Volume = 63;
- Audio_Request->ioa_Cycles = 100;
- return(0);
- }
-
-
- beep()
- {
- if(beepok) {
- Audio_Request->ioa_Volume = 63;
- BeginIO((struct IORequest *)Audio_Request);
- WaitIO((struct IORequest *)Audio_Request);
- }
- }
- donebeep()
- {
- if(beepok) {
- if(Audio_Request) {
- CloseDevice((struct IORequest *)Audio_Request);
- FreeMem(Audio_Request,sizeof(*Audio_Request));
- Audio_Request = 0;
- }
- if(Audio_Port)DeletePort(Audio_Port);
- if(BeepWave)FreeMem(BeepWave,BEEPSIZE);
- }
- }
-
-